import { Component, EventEmitter, Input, OnInit, Output, SimpleChanges } from '@angular/core';
import { ApesFormatEmitEvent } from '@shared/apes/core';

interface Node {
  key: string;
  title: string;

  [propName: string]: any;
}

@Component({
  selector: 'epc-standard-menu',
  templateUrl: './epc-standard-menu.component.html',
  styleUrls: ['./epc-standard-menu.component.scss'],
})

export class EpcStandardMenuComponent implements OnInit {

  @Input()isloading: boolean;
  @Input() nodes;
  @Output() selected = new EventEmitter();

  listNodes = [];
  selectNode: any = {};

  ngOnChanges(changes: SimpleChanges): void {
    if (changes.nodes) {
      this.listNodes = changes.nodes.currentValue &&
      changes.nodes.currentValue.length > 0 ?
        changes.nodes.currentValue : [];
    }
  }

  clickHandle(event: Event, node: Node): void {
    if (this.isloading) {
      return;
    }
    this.selectNode = node;
    this.selected.emit(node);
    this.isloading = true;
  }

  ngOnInit(): void {
  }
}
